//
//  IMJinDouMessageTableViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/6/23.
//

#import "IMJinDouMessageTableViewCell.h"

@implementation IMJinDouMessageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self.bgView = [[UIView alloc]init];
    self.bgView.layer.cornerRadius = 10;
    self.bgView.layer.masksToBounds = YES;
   
    [self.contentView addSubview:self.bgView];
    
    [self.contentView addSubview:self.messageTextView];
    [self.messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.avatarImageView).offset(6);
        make.left.equalTo(self.contentView).offset(10+12+48);
    }];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.messageTextView).insets(UIEdgeInsetsMake(-4, -46, -4, -6));
    }];
    [self.contentView addSubview:self.blackImageView];
    [self.blackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(24);
        make.right.equalTo(self.bgView.mas_left).offset(-4);
        make.bottom.equalTo(self.bgView.mas_bottom);
    }];
    
   self.imageLeft = [[UIImageView alloc]init];
    self.imageLeft.image = SQGetImage(@"豆子");
    self.imageLeft.contentMode = UIViewContentModeScaleAspectFit;
    [self.bgView addSubview:self.imageLeft];
    [self.imageLeft mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(22);
            make.centerY.equalTo(self.bgView);
            make.left.equalTo(self.bgView).offset(16);
    }];
    
}

- (void)setModel:(IMMessageModel *)model{
    [super setModel:model];
    
    self.messageTextView.text = model.content;
    [self.messageTextView mas_updateConstraints:^(MASConstraintMaker *make) {
        if (model.sendType) {
            make.left.equalTo(self.contentView).offset(12+48+10 + 6 + 40);
        } else {
            make.left.equalTo(self.contentView).offset(SCREEN_WIDETH-12-48-10-model.cellSize.width-6);
        }
        make.width.mas_equalTo(model.cellSize.width);
        make.height.mas_equalTo(model.cellSize.height);
    }];
    if (self.model.sendType) {
        self.bgView.backgroundColor = SQColor(@"#F0F8FF");
        self.messageTextView.textColor = UIColor.blackColor;
    } else {
        self.bgView.backgroundColor = SQColor666666;
        self.messageTextView.textColor = UIColor.whiteColor;
    }
     [self.contentView layoutIfNeeded];
}
- (SJCustomSelectTextView *)messageTextView{
    if (!_messageTextView) {
        _messageTextView = [[SJCustomSelectTextView alloc]init];
        _messageTextView.backgroundColor = UIColor.clearColor;
//        _messageTextView.layer.cornerRadius = 20;
//        _messageTextView.layer.masksToBounds = YES;
        _messageTextView.font = FONT_MEDIUM(15);
        _messageTextView.textColor = UIColor.whiteColor;
        _messageTextView.editable = NO;
        _messageTextView.selectable = YES;
//        _messageTextView.userInteractionEnabled = NO;
    }
    return _messageTextView;
}
@end
